package thread.parral;

import java.util.concurrent.CountDownLatch;

public
//1114. 按序打印
class Foo {
    
    public Foo() {
        
    }
    
    public void first(Runnable printFirst) throws InterruptedException {
        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        firstJobDone.countDown();
    }
    
    public void second(Runnable printSecond) throws InterruptedException {
        firstJobDone.await();
        
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        secondJobDone.countDown();
    }
    
    public void third(Runnable printThird) throws InterruptedException {
        secondJobDone.await();
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
    
    private CountDownLatch firstJobDone = new CountDownLatch(1);
    private CountDownLatch secondJobDone = new CountDownLatch(1);
    // private AtomicInteger firstJobDone = new AtomicInteger(0);
    // private AtomicInteger secondJobDone = new AtomicInteger(0);
    
    // volatile boolean firstSecondJob = false;
    // volatile boolean secondThirdJob = false;
    
}